package com.ysp.summary.controller;

import org.apache.commons.lang3.StringUtils;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("ysp")
public class TestController {

    @Autowired
    private StringEncryptor encryptor;

    @Value("${ysp.config:ysp}")
    private String yspConfig;

    @GetMapping("info")
    public String getInfo(){
        return "杨工 高工 丽丽 : "+System.currentTimeMillis();
    }

    @GetMapping("config")
    public String getConfig(){
        return yspConfig;
    }

    @GetMapping("jasypt")
    public String getJasypt(String password){
        if (StringUtils.isBlank(password)){
            throw new RuntimeException("加密字符串不能为空");
        }
        String encryPwd = encryptor.encrypt(password);
        String decrypwd = encryptor.decrypt(encryPwd);
        System.out.println("解密后输出："+decrypwd);
        return encryPwd;
    }

}
